Proper connect_port
[juce-lv2.git] / juce / source / extras / the jucer / src / properties / jucer_FontPropertyComponent.cpp
blob3070780a11a575f85fc0c47e941c511da0113e29
1 /*
2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #include "../jucer_Headers.h"
27 #include "jucer_FontPropertyComponent.h"
30 //==============================================================================
31 class FontList : public DeletedAtShutdown
33 public:
34 FontList()
36 Array<Font> fonts;
37 Font::findFonts (fonts);
39 for (int i = 0; i < fonts.size(); ++i)
40 fontNames.add (fonts[i].getTypefaceName());
43 ~FontList()
45 clearSingletonInstance();
48 juce_DeclareSingleton_SingleThreaded_Minimal (FontList)
50 StringArray fontNames;
53 juce_ImplementSingleton_SingleThreaded (FontList)
55 void FontPropertyComponent::preloadAllFonts()
57 FontList::getInstance();
60 //==============================================================================
61 const String FontPropertyComponent::defaultFont ("Default font");
62 const String FontPropertyComponent::defaultSans ("Default sans-serif font");
63 const String FontPropertyComponent::defaultSerif ("Default serif font");
64 const String FontPropertyComponent::defaultMono ("Default monospaced font");
66 FontPropertyComponent::FontPropertyComponent (const String& name)
67 : ChoicePropertyComponent (name)
69 choices.add (defaultFont);
70 choices.add (defaultSans);
71 choices.add (defaultSerif);
72 choices.add (defaultMono);
73 choices.add (String::empty);
75 choices.addArray (FontList::getInstance()->fontNames);
78 FontPropertyComponent::~FontPropertyComponent()
82 //==============================================================================
83 void FontPropertyComponent::setIndex (const int newIndex)
85 String type (choices [newIndex]);
87 if (type.isEmpty())
88 type = defaultFont;
90 if (getTypefaceName() != type)
91 setTypefaceName (type);
94 int FontPropertyComponent::getIndex() const
96 return choices.indexOf (getTypefaceName());
99 const Font FontPropertyComponent::applyNameToFont (const String& typefaceName, const Font& font)
101 if (typefaceName == defaultFont)
102 return Font (font.getHeight(), font.getStyleFlags());
103 else if (typefaceName == defaultSans)
104 return Font (Font::getDefaultSansSerifFontName(), font.getHeight(), font.getStyleFlags());
105 else if (typefaceName == defaultSerif)
106 return Font (Font::getDefaultSerifFontName(), font.getHeight(), font.getStyleFlags());
107 else if (typefaceName == defaultMono)
108 return Font (Font::getDefaultMonospacedFontName(), font.getHeight(), font.getStyleFlags());
110 return Font (typefaceName, font.getHeight(), font.getStyleFlags());
113 const String FontPropertyComponent::getTypefaceNameCode (const String& typefaceName)
115 if (typefaceName == defaultFont)
116 return String::empty;
117 else if (typefaceName == defaultSans)
118 return "Font::getDefaultSansSerifFontName(), ";
119 else if (typefaceName == defaultSerif)
120 return "Font::getDefaultSerifFontName(), ";
121 else if (typefaceName == defaultMono)
122 return "Font::getDefaultMonospacedFontName(), ";
124 return "L\"" + typefaceName + "\", ";
127 const String FontPropertyComponent::getFontStyleCode (const Font& font)
129 if (font.isBold() && font.isItalic())
130 return "Font::bold | Font::italic";
131 else if (font.isBold())
132 return "Font::bold";
133 else if (font.isItalic())
134 return "Font::italic";
136 return "Font::plain";
139 const String FontPropertyComponent::getCompleteFontCode (const Font& font, const String& typefaceName)
141 return "Font ("
142 + getTypefaceNameCode (typefaceName)
143 + valueToFloat (font.getHeight())
144 + ", "
145 + getFontStyleCode (font)
146 + ")";